<template>
	<view>
		<view class="u-m-b-20">
			<el-button @click="asyncAll(0)">全部同步</el-button>
		</view>

		<el-table :data="dataList" style="width: 100%" stripe border size="mini" height="800px">
			<el-table-column type="index" width="50" label="序号" />
			<el-table-column prop="id" label="id" width="150" />
			<el-table-column prop="text" label="标题" width="150" />

			<el-table-column prop="isAsync" label="是否已同步" width="180">
				<template slot-scope="scope">
					<view v-if="scope.row.isAsync" class="u-type-success">已同步</view>
					<view v-else class="u-type-warning">未同步</view>
				</template>
			</el-table-column>

			<el-table-column prop="tid" label="模板id">
			</el-table-column>


			<el-table-column fixed="right" label="操作" width="150" align="center">
				<!-- <template slot-scope="scope">
					<el-button @click="deleteThis(scope.row)" type="text" size="small">删除</el-button>
					<el-button type="text" size="small" @click="editThis(scope.row)">编辑</el-button>
				</template> -->
			</el-table-column>
		</el-table>
	</view>
</template>

<script>
	let that
	export default {
		data() {
			return {
				dataList: []
			}
		},

		onLoad() {
			that = this
			that.getList()
		},

		methods: {
			asyncAll(index = 0) {
				if (index == that.dataList.length) return that.common.showToast("同步完成")
				let item = that.dataList[index]
				
				if (item.content == '') return that.asyncAll(index + 1)
				let thisImages = []
				for (let _img of item.images) {
					thisImages.push(_img.url)
				}
				
				this.$http.Post("admin/artPainting/save", {
					nameZh: item.content,
					images: thisImages
				}, "加载中...").then(res => {
					item.isAsync = true
					return that.asyncAll(index + 1)
				})
			},

			getList() {
				uni.request({
					url: "https://poster.miaogeban.com/poster/shareText/list?pageSize=20000&pageNum=1&type=2&typeName=&typeId=&rids=",
					data: {},
					method: 'GET',
					header: {
						"content-type": "application/json",
					},
					timeout: 6000000000,
					success: (res) => {
						console.log(res)
						let dataList = res.data.data.rows
						let ids = []
						for (let item of dataList) {
							ids.push(item.id)
						}
						that.dataList = dataList

						// this.$http.Post("admin/artPainting/list", {
						// 	ids: ids
						// }, "加载中...").then(res => {
						// 	let existList = res.data
						// 	for (let item of dataList) {
						// 		item.isAsync = false
						// 		let thisIndex = existList.findIndex(item2 => item2.nameZh == item.content)
						// 		console.log(thisIndex)
						// 		if (thisIndex != -1) item.isAsync = true
						// 	}
						// 	that.dataList = dataList
						// 	that.$forceUpdate()
						// })
					},
				})
			}
		}
	}
</script>

<style>

</style>